package com.example.example5_2;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Intent intent = new Intent(MainActivity.this, MyAudioService.class);
        ServiceConnection conn = new ServiceConnection() {

            @Override
            public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
                MyAudioService.PlayBinder playBinder = (MyAudioService.PlayBinder) iBinder;
                playBinder.MyMethod();
            }

            @Override
            public void onServiceDisconnected(ComponentName componentName) {

            }
        };
        intent.setAction("com.example.example5_2");
        intent.setPackage("com.example.example5_2");
        bindService(intent,conn,BIND_AUTO_CREATE);
    }
}

interface ServiceConnection extends android.content.ServiceConnection {
    @Override
    void onServiceConnected(ComponentName componentName, IBinder iBinder);

    @Override
    void onServiceDisconnected(ComponentName componentName);
}